package com.music.controller;

import com.music.dto.Result;
import com.music.entity.PlaylistVo;
import com.music.entity.UserPlayList;
import com.music.service.PlaylistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

/**
 * @author 名一
 * @ClassName PlayListController
 * @description: TODO
 * @datetime 2022年 07月 08日 13:57
 * @version: 1.0
 */
@RestController
@RequestMapping("/playlist")
public class PlayListController {

    @Autowired
    private PlaylistService playlistService;

    @GetMapping()
    public Result getPlayList(){
        Result result = new Result();
        List<PlaylistVo> playlistVoList = playlistService.getPlaylistByUser();
        if (!playlistVoList.isEmpty()) {
            result.ok(playlistVoList);
        }else{
            result.fail(0,"没有数据");
        }
        /*Optional.ofNullable(playlistVoList).ifPresent(list->{

        });*/
        return result;
    }

    @RequestMapping("/addOne")
    public Result addSongToPlaylist(@RequestParam Integer songId){
        Result result = new Result();
        playlistService.addSong(songId);
        return result.ok(true);
    }

    @RequestMapping("/addSonglist")
    public Result addSonglistToPlaylist(@RequestBody List<Integer> songIdList){
        Result result = new Result();
        playlistService.addSonglist(songIdList);
        return result.ok(true);
    }
}
